package com.sheng.sign.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.sheng.sign.entity.Course;
import com.sheng.sign.service.CourseService;

public class CourseAction extends ActionSupport implements ModelDriven<Course>{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -1928443106872195634L;
	protected String forwardView;
	protected static final String SUCCESS_JSP = "/success.jsp";
	protected static final String ADD_JSP = "/page/Course_add.jsp";
	protected static final String EDIT_JSP = "/page/Course_edit.jsp";
	protected static final String LIST_JSP = "/page/Course_list.jsp";
	
	private List<Course> lists ;
	private Course course = new Course();
	private CourseService courseService;
	
	public Course getModel() {
		return course;
	}
	public String openAdd() {
		setForwardView(ADD_JSP);
		return SUCCESS;
	}
	public String openEdit(){
		course = courseService.findById(course);
		System.out.println("==来到了openEditAction===值："+course.getId()+";"+course.getCourseName()+";"+course.getCourseId()+";"+course.getIsDelete());
			setForwardView(EDIT_JSP);
			return SUCCESS;
	}
	 
	/**
	 * 
	 * @Description:添加
	 * @return
	 * String
	 * @exception:
	 * @author: huangshengjun 1532950421@qq.com
	 * @time:2019年12月7日 下午8:12:07
	 */
	public String add() {
		course.setIsDelete(0);
		System.out.println("==来到了addAction== "+course);
		boolean value = courseService.add(course);
		if(value){
			setForwardView(LIST_JSP);
			return this.list();
		}else{
			return ERROR;
		}
	}
	/**
	 * 
	 * @Description:TODO描述
	 * @return
	 * String
	 * @exception:
	 * @author: huangshengjun 1532950421@qq.com
	 * @time:2019年12月7日 下午8:12:40
	 */
	public String edit() {
		System.out.println("==来到了editAction== "+course);
		boolean value = courseService.edit(course);
		if(value){
			return this.list();
		}else{
			return ERROR;
		}
	}
	/**
	 * 
	 * @Description:TODO描述
	 * @return
	 * String
	 * @exception:
	 * @author: huangshengjun 1532950421@qq.com
	 * @time:2019年12月7日 下午8:12:48
	 */
	public String delete() {
		course = courseService.findById(course);
		System.out.println("==来到了delAction== "+course);
		boolean value = courseService.delete(course);
		if(value){
			return this.list();
		}else{
			return ERROR;
		}
	}
	
	/**
	 * 
	 * @Description:信息列表
	 * @return 关于课程的list集合
	 * String
	 * @exception:
	 * @author: huangshengjun 1532950421@qq.com
	 * @time:2019年12月7日 下午8:12:55
	 */
	public String list() {
		lists = courseService.findAllList();
		System.out.println("Action的课程列表==="+lists);
		setForwardView(LIST_JSP);
		return SUCCESS;
	}
	
	public String findByCourseName() {
		lists = courseService.findByCourseName(course);
		setForwardView(LIST_JSP);
		return SUCCESS;
	}

	public String getForwardView() {
		return forwardView;
	}

	public void setForwardView(String forwardView) {
		this.forwardView = forwardView;
	}

	public CourseService getCourseService() {
		return courseService;
	}

	public void setCourseService(CourseService courseService) {
		this.courseService = courseService;
	}

	public Course getCourse() {
		return course;
	}

	public void setCourse(Course course) {
		this.course = course;
	}
	public List<Course> getLists() {
		return lists;
	}
	public void setLists(List<Course> lists) {
		this.lists = lists;
	}
}
